<template>
  <j-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    switchFullscreen
    @ok="handleSubmit"
    @cancel="close"
    style="top: 50px"
    cancelText="关闭"
  >
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="编号">
                <a-input placeholder="请输入编号" v-model="queryParam.code"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="名称">
                <a-input placeholder="请输入名称" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
            <template v-if="toggleSearchStatus">
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="联系人">
                  <a-input placeholder="请输入联系人" v-model="queryParam.contact"></a-input>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="状态">
                  <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="erp_status" />
                </a-form-item>
              </a-col>
            </template>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                <a @click="handleToggleSearch" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
                </a>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->
      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
          <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
          >项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <a-table
          ref="table"
          size="middle"
          :scroll="{ x: true }"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: checkval }"
          class="j-table-force-nowrap1"
          @change="handleTableChange"
          :customRow="customClick"
        />
      </div>
    </a-card>
  </j-modal>
</template>
<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { filterObj } from '@/utils/util'

export default {
  name: 'ErpGoodsSupplierListModel',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  // props: ['category', "modalWidth",],
  props: {
    category: {
      type: String,
    },
    modalWidth: {
      type: Number,
      required: false,
      default: 1250,
    },
    checkval: {
      type: String,
      default: 'radio',
    },
    materialId: {
      type: String,
    },
  },
  data() {
    return {
      description: '供应商管理页面',
      visible: false,
      title: '选择供应商',
      queryParam: { categoryCode: this.category, goodsId: this.materialId },
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '编号',
          align: 'center',
          dataIndex: 'code',
        },
        {
          title: '名称',
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: '联系人',
          align: 'center',
          dataIndex: 'contact',
        },
        {
          title: '电话',
          align: 'center',
          dataIndex: 'telephone',
        },
        {
          title: '邮箱',
          align: 'center',
          dataIndex: 'email',
        },
        {
          title: '传真',
          align: 'center',
          dataIndex: 'fax',
        },
        {
          title: '地址',
          align: 'center',
          dataIndex: 'address',
        },
        {
          title: '开户行',
          align: 'center',
          dataIndex: 'bankName',
        },
        {
          title: '账号',
          align: 'center',
          dataIndex: 'accountNo',
        },
        {
          title: '邮编',
          align: 'center',
          dataIndex: 'zipCode',
        },
      ],
      url: {
        list: '/base/erpSupplier/list',
        delete: '/base/erpGoodsSupplier/delete',
        deleteBatch: '/base/erpGoodsSupplier/deleteBatch',
        exportXlsUrl: '/base/erpGoodsSupplier/exportXls',
        importExcelUrl: 'base/erpGoodsSupplier/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    handleSubmit() {
      this.getGoodsSupplierSelectRows()
      this.searchReset(false)
      this.onClearSelected()
      this.close()
    },
    add() {
      this.showModal()
    },
    showModal() {
      this.visible = true
      this.loadData()
    },
    getGoodsSupplierSelectRows() {
      let selectedRow = null
      if (this.checkval == 'radio') {
        selectedRow = this.selectionRows[0]
      } else {
        selectedRow = this.selectedRowKeys
      }
      // let selectedRow = this.selectionRows[0];
      //传递选中的数据
      this.$emit('supplierOk', selectedRow)
    },
    initDictConfig() {},
    close() {
      this.searchReset(false)
      this.visible = false
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'code', text: '编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'name', text: '名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'contact', text: '联系人', dictCode: '' })
      this.superFieldList = fieldList
    },
    customClick(row) {
      var that = this
      return {
        on: {
          dblclick: () => {
            that.$emit('supplierOk', row)
            that.close()
          },
        },
      }
    },
    //重新传参
    getQueryParams() {
      //重新写入传参 按照模糊查询
      let curParam = {}
      Object.assign(curParam, this.queryParam)
      if (curParam.code) {
        curParam.code = '*' + this.queryParam.code + '*'
      }
      if (curParam.name) {
        curParam.name = '*' + this.queryParam.name + '*'
      }
      //获取查询条件
      let sqp = {}
      if (this.superQueryParams) {
        sqp['superQueryParams'] = encodeURI(this.superQueryParams)
        sqp['superQueryMatchType'] = this.superQueryMatchType
      }
      var param = Object.assign(sqp, curParam, this.isorter, this.filters)
      param.field = this.getQueryField()
      param.pageNo = this.ipagination.current
      param.pageSize = this.ipagination.pageSize
      return filterObj(param)
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
